package GlavFinans::Module::Core;

use Modern::Perl;

use Data::Dumper;
use Mojo::Base 'Mojolicious';
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Loader;

has 'app';
has config => sub {{}};
has name => 'core';

sub register {
	my ($self, $app, $conf) = @_;

	$self->app($app);
	$self->config($app->config);
	
	my $modules = $self->config->{modules};
	foreach  ( @$modules ) {
		$app->plugin( sprintf ('GlavFinans::Module::%s', $_), config => $app->config );
	}
	
	$app->routes->namespace('GlavFinans::Module::Core::Controller');
	
	my $r = $app->routes->bridge->to( controller => 'Auth', 
							 			action => 'checkSession',
							 			layout => 'customer');
	
	my $route = {
		'anon' => {
			'bridge'    => $r,
			'layout'    => 'frontend',
			'namespace' => 'GlavFinans::Module::Core::Controller',
			'route'     => [
				['get',   '/',         'Front',   'index',  'core_front_index'],
				['get',   '/captcha',  'Captcha', 'index',  'core_captcha_index'],
				['get',   '/logout',   'Auth',    'logout', 'core_auth_logout'],
				['route', '/login',    'Auth',    'login',  'core_auth_login'],
				['get',   '/lostpw',   'Auth',    'lostpw', 'core_auth_lostpw'],
				['get',   '/contact',  'Contact', 'form',   'core_contact_form'],
				['post',  '/contact',  'Contact', 'create', 'core_contact_create']
			]
		}
	};
	
	$app->route($route);
}
1;
